package com.dkm.ec.address.repository.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.ou.persistence.entity.AddrPo;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.address.domain.UserAddress;
import com.dkm.ec.address.repository.UserAddressRepository;
import com.dkm.ec.address.persistence.dao.UserAddressQueryDao;
import com.dkm.ec.address.persistence.entity.UserAddressPo;

/**
 * 对象功能:user_address Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-08-18 14:33:11
 */
@Repository
public class UserAddressRepositoryImpl extends AbstractRepository<String, UserAddressPo,UserAddress> implements UserAddressRepository{
	  
	@Resource
	private  UserAddressQueryDao userAddressQueryDao;

	public UserAddress newInstance() {
		UserAddressPo po = new UserAddressPo();
		UserAddress userAddress = SpringHelper.getBean(UserAddress.class);
		userAddress.setData(po);
		return userAddress;
	}

	public UserAddress newInstance(UserAddressPo po) {
		UserAddress userAddress = SpringHelper.getBean(UserAddress.class);
		userAddress.setData(po);
		return userAddress;
	} 
	
	@Override
	protected IQueryDao<String, UserAddressPo> getQueryDao() {
		return userAddressQueryDao;
	}

	@Override
	public UserAddressPo findByPartyid(String zmzUserId) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuffer buffer = new StringBuffer();
		buffer.append("user_id='"+zmzUserId+"'");
		buffer.append(" and default_flag=1");
		params.put("whereSql", buffer.toString());
		List<UserAddressPo> addrPos = findAll(params);
		if(addrPos.size() > 0){
			UserAddressPo  addrPo2 = addrPos.get(0);
			return addrPo2;
		}
		return null;
	}
	
}
